package br.com.toscano.gobra.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

@Entity 
@Table(name="TABELA_PRECO")
public class TabelaPreco  extends ObjetoAbstrato {

	private static final long serialVersionUID = 13454534543354516L;

	public Object getValorDescricao() {
		return this.getDescricao();
	}

	public String getLabelAtributoDescricao() {return "Descrição";}public String getAtributoDescricao() {
		return "descricao";
	}

	public Object getKey() {
		return this.getId();
	}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="TBPR_ID")
	private Long id;

	@Column(name="TBPR_DESCRICAO", nullable=false, length=255)
	private String descricao;
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "tabelaPreco", orphanRemoval = true)
	@Cascade(value={org.hibernate.annotations.CascadeType.PERSIST, org.hibernate.annotations.CascadeType.MERGE})
	private List<ItemTabelaPreco> listaItemTabelaPrecos= new ArrayList<ItemTabelaPreco>();
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getDescricao() {
		return descricao;
	}
	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	public List<ItemTabelaPreco> getListaItemTabelaPrecos() {
		return listaItemTabelaPrecos;
	}

	public void setListaItemTabelaPrecos(List<ItemTabelaPreco> listaItemTabelaPrecos) {
		this.listaItemTabelaPrecos = listaItemTabelaPrecos;
	}
	
	




	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if(!this.getClass().equals(obj.getClass()))
			return false;
		if (getClass() != obj.getClass())
			return false;
		TabelaPreco other = (TabelaPreco) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	
}